From 838aa9196861afd9c1d14bf83f13eaff254136a2 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Mon, 18 Mar 2024 16:50:00 -0500 Subject: [PATCH] Change super() calls from python2 style to python3 --- src/pgwui_core/core.py | 33 ++++++++++++++++----------------- src/pgwui_core/exceptions.py | 34 +++++++++++++++++----------------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/pgwui_core/core.py b/src/pgwui_core/core.py index 41e141a..e01d4f8 100644 --- a/src/pgwui_core/core.py +++ b/src/pgwui_core/core.py @@ -775,7 +775,7 @@ class UploadLine(object): mapper(st) Maps st onto desired python representation (Used for trimming whitespace) ''' - super(UploadLine, self).__init__() + super().__init__() self.raw = line self.tuples = [mapper(st) for st in stol(line)] @@ -813,7 +813,7 @@ class UploadHeaders(UploadLine): 'No column headings found on first line', 'The first line is ({0})'.format(line)) - super(UploadHeaders, self).__init__(line, stol, mapper) + super().__init__(line, stol, mapper) self.sql = ', '.join(['"' + doublequote(st) + '"' for st in self.tuples]) @@ -828,7 +828,7 @@ class UploadDataLine(UploadLine): lineno The line number ''' def __init__(self, line, lineno, stol, mapper): - super(UploadDataLine, self).__init__(line, stol, mapper) + super().__init__(line, stol, mapper) self.lineno = lineno @@ -867,7 +867,7 @@ class SQLData(DBData): ''' stmts List of SQLCommand instances ''' - super(SQLData, self).__init__() + super().__init__() self.stmts = stmts def _thunk(self): @@ -967,7 +967,7 @@ class UploadData(DBData): return st.split('\t') return (eol, UploadHeaders(line, func, do_trim)) - super(UploadData, self).__init__() + super().__init__() if trim: def do_trim(st): @@ -1104,7 +1104,7 @@ class DataLineProcessor(object): ue UploadEngine instance uh UploadHandler instance ''' - super(DataLineProcessor, self).__init__() + super().__init__() self.ue = ue self.uh = uh self.cur = ue.cur @@ -1126,7 +1126,7 @@ class NoOpProcessor(DataLineProcessor): uh UploadHandler instance cur psycopg3 cursor ''' - super(NoOpProcessor, self).__init__(ue, uh) + super().__init__(ue, uh) def eat(self, udl): ''' @@ -1144,7 +1144,7 @@ class ExecuteSQL(DataLineProcessor): uh UploadHandler instance cur psycopg3 cursor ''' - super(ExecuteSQL, self).__init__(ue, uh) + super().__init__(ue, uh) def eat(self, sqlc): ''' @@ -1298,7 +1298,7 @@ class SessionDBHandler(DBHandler): errors A list of core_ex.UploadError exceptions. csrf_token Token for detecting CSRF. ''' - response = super(SessionDBHandler, self).write(result, errors) + response = super().write(result, errors) response['csrf_token'] = self.session.new_csrf_token() return response @@ -1329,7 +1329,7 @@ class UploadHandler(SessionDBHandler): A list of Error instances ''' uf = self.uf - errors = super(UploadHandler, self).val_input() + errors = super().val_input() if uf['filename'] == '': errors.append(core_ex.NoFileError('No file supplied')) @@ -1468,7 +1468,7 @@ class DBConnector(object): ''' uh An UploadHandler instance ''' - super(DBConnector, self).__init__() + super().__init__() # Configuration and response management. self.uh = uh @@ -1755,7 +1755,7 @@ class NoTransactionEngine(DBConnector): ''' uh An UploadHandler instance ''' - super(NoTransactionEngine, self).__init__(uh) + super().__init__(uh) def _call_alter_db(self, func, conn): ''' @@ -1834,7 +1834,7 @@ class UnsafeUploadEngine(DBConnector): ''' uh An UploadHandler instance ''' - super(UnsafeUploadEngine, self).__init__(uh) + super().__init__(uh) def _call_alter_db(self, func, conn): ''' @@ -1947,7 +1947,7 @@ class UploadEngine(UnsafeUploadEngine): ''' uh An UploadHandler instance ''' - super(UploadEngine, self).__init__(uh) + super().__init__(uh) def csrferror_factory(self): return core_ex.CSRFError( @@ -1977,7 +1977,7 @@ class UploadEngine(UnsafeUploadEngine): def read(self): '''Add a csrf_token.''' - super(UploadEngine, self).read() + super().read() self.read_csrf_token() def call_with_connection(self, func): @@ -2011,7 +2011,6 @@ class UploadEngine(UnsafeUploadEngine): return ([self.csrferror_factory()], response) else: - (errors, response) = (super(UploadEngine, self) - .call_with_connection(func)) + (errors, response) = super().call_with_connection(func) response['session_expired'] = False return (errors, response) diff --git a/src/pgwui_core/exceptions.py b/src/pgwui_core/exceptions.py index d6d7c2a..0fd7b1f 100644 --- a/src/pgwui_core/exceptions.py +++ b/src/pgwui_core/exceptions.py @@ -71,7 +71,7 @@ class UploadError(PGWUIError): * TooManyColsError ''' def __init__(self, e, lineno='', descr='', detail='', data=''): - super(UploadError, self).__init__() + super().__init__() self.lineno = lineno self.e = e self.descr = descr @@ -112,55 +112,55 @@ class SetupError(UploadError): detail Extra HTML describing the error ''' def __init__(self, e, descr='', detail=''): - super(SetupError, self).__init__(e=e, descr=descr, detail=detail) + super().__init__(e=e, descr=descr, detail=detail) class NoFileError(SetupError): '''No file uploaded''' def __init__(self, e, descr='', detail=''): - super(NoFileError, self).__init__(e, descr, detail) + super().__init__(e, descr, detail) class NoDBError(SetupError): '''No database name given''' def __init__(self, e, descr='', detail=''): - super(NoDBError, self).__init__(e, descr, detail) + super().__init__(e, descr, detail) class NoUserError(SetupError): '''No user name supplied''' def __init__(self, e, descr='', detail=''): - super(NoUserError, self).__init__(e, descr, detail) + super().__init__(e, descr, detail) class AuthFailError(SetupError): '''Unable to connect to the db''' def __init__(self, e, descr='', detail=''): - super(AuthFailError, self).__init__(e, descr, detail) + super().__init__(e, descr, detail) class DryRunError(SetupError): '''Rollback due to dry_run config option''' def __init__(self, e, descr='', detail=''): - super(DryRunError, self).__init__(e, descr, detail) + super().__init__(e, descr, detail) class CSRFError(SetupError): '''Invalid CSRF token''' def __init__(self, e, descr='', detail=''): - super(CSRFError, self).__init__(e, descr, detail) + super().__init__(e, descr, detail) class NoHeadersError(SetupError): '''No column headings found''' def __init__(self, e, descr='', detail=''): - super(NoHeadersError, self).__init__(e, descr, detail) + super().__init__(e, descr, detail) class NoDataError(SetupError): '''No data uploaded''' def __init__(self, e, descr='', detail=''): - super(NoDataError, self).__init__(e, descr, detail) + super().__init__(e, descr, detail) class CantDecodeError(SetupError): @@ -172,12 +172,12 @@ class CantDecodeError(SetupError): class DuplicateUploadError(SetupError): '''The same filename updated twice into the same db''' def __init__(self, e, descr='', detail=''): - super(DuplicateUploadError, self).__init__(e, descr, detail) + super().__init__(e, descr, detail) class DataInconsistencyError(SetupError): def __init__(self, e, descr='', detail=''): - super(DataInconsistencyError, self).__init__(e, descr, detail) + super().__init__(e, descr, detail) class SQLEncodingError(SetupError): @@ -194,7 +194,7 @@ class DBError(SetupError): pgexc The psycopg3 exception object e Description of what PG was doing ''' - super(DBError, self).__init__( + super().__init__( 'PostgreSQL is unable to ' + e + ':', 'It reports:', self.html_blockquote(pgexc)) @@ -225,7 +225,7 @@ class DBError(SetupError): class DBCommitError(DBError): def __init__(self, pgexc): - super(DBCommitError, self).__init__(pgexc) + super().__init__(pgexc) class DBDataLineError(DBError): @@ -236,7 +236,7 @@ class DBDataLineError(DBError): udl An UploadDataLine instance pgexc The psycopg3 exception object ''' - super(DBDataLineError, self).__init__(pgexc) + super().__init__(pgexc) self.lineno = udl.lineno self.data = udl.raw @@ -258,12 +258,12 @@ class DataLineError(UploadError): data The uploaded data ''' def __init__(self, lineno, e, descr='', detail='', data=''): - super(DataLineError, self).__init__(e, lineno, descr, detail, data) + super().__init__(e, lineno, descr, detail, data) class TooManyColsError(DataLineError): def __init__(self, lineno, e, descr='', detail='', data=''): - super(TooManyColsError, self).__init__(lineno, e, descr, detail, data) + super().__init__(lineno, e, descr, detail, data) class TooFewColsError(DataLineError): -- 2.34.1